/*
 *动态添加行
 * my
*/
function createRow(id) {
    var row =  parseInt($("#contentTable").find("tr").length);
    if(row>1){
        $("#msg").html("");
    }
    $("#contentTable tr:last").after(
        '<tr class="tr">'+
        '<td class="sort"></td>'+
        '<td ><input name="list[].breedLivestock" htmlEscape="false" maxlength="20" class="input-xlarge per-name input" required="required" style="width:220px;height:25px;"/></td>'+
        '<td ><input name="list[].totalInventory" htmlEscape="false" maxlength="11" class="input-xlarge per-price input" required="required" style="width:220px;height:25px;" onBlur="checkPhone()"/></td>'+
        '<td ><input name="list[].breedingStock" htmlEscape="false" maxlength="11" class="input-xlarge per-stock input" required="required" style="width:220px;height:25px;" onBlur="checkPhone()"/></td>'+
        '<td ><input name="list[].quantityOfSlaughter" htmlEscape="false" maxlength="11" class="input-xlarge per-stock input" required="required" style="width:220px;height:25px;" onBlur="checkPhone()"/></td>'+
        '<td ><a href="javascript:;" onclick="delRow(this)">删除</a></td>'+
        '</tr>'
    );
    changeIndex();
}
/*
 *动态删除行
 * my
 */
function delRow(obj) {
    if($("#contentTable").find("tr").length<3){
        $("#msg").html("必填项，不能删除！");
    }else{
        $(obj).parent().parent().remove();
        changeIndex();
    }
}

/*
 *排序
 * my
 */
function changeIndex(){
    //解决首列排序号
    // $("#contentTable").find("tr").each(function (i,n) {
    //     $(n).find("td:eq(0)").text(i);
    // });
    //
    // $(".per-breedLivestock").each(function (i,n) {
    //     $(n).attr("name",'farmClass.list['+i+'].breedLivestock');
    // });
    // $(".per-totalInventory").each(function (i,n) {
    //     $(n).attr("name",'farmClass.list['+i+'].totalInventory');
    // });
    // $(".per-breedingStock").each(function (i,n) {
    //     $(n).attr("name",'farmClass.list['+i+'].breedingStock');
    // });
    // $(".per-quantityOfSlaughter").each(function (i,n) {
    //     $(n).attr("name",'farmClass.list['+i+'].quantityOfSlaughter');
    // });
    $(".tr").each(function (i,row) {
        $($(row).find(".sort")[0]).html(i+1)
        $(row).find(".input").each(function (iii,input) {
            let name=$(input).attr("name");
            $(input).attr("name",name.replace('[]','['+i+']'))
        })
    })

}
